﻿namespace WebApplication1
{
    [Serializable]
    public class Order
    {
        private int id;
        private string customer;
        private string address;
        private string phoneNumber;
        private OrderDetails details;
        //{
        //    "customer": "Sandy",
        //    "address": "WHU",
        //    "phoneNumber": "134321",
        //    "details": {
        //        "deposit": 0,
        //        "orderDate": "2022-05-10T13:41:44.325221+08:00",
        //        "goods": [
        //            {
        //                "name": "C",
        //                "num": 1,
        //                "price": 5
        //            }
        //        ]
        //    }
        //}
        public Order()
        {
            this.id = 0;
            this.customer = "";
            this.address = "";
            this.phoneNumber = "";
            this.details = new OrderDetails();
        }
        public Order(string customer, string address, string phoneNumber, OrderDetails details)
        {
            this.customer = customer;
            this.address = address;
            this.phoneNumber = phoneNumber;
            this.details = details;
        }
        public Order(int id, string customer, string address, string phoneNumber, OrderDetails details)
        {
            this.id = id;
            this.customer = customer;
            this.address = address;
            this.phoneNumber = phoneNumber;
            this.details = details;
        }

        public int Id { get => id; set => id = value; }
        public string Customer { get => customer; set => customer = value; }
        public string Address { get => address; set => address = value; }
        public string PhoneNumber { get => phoneNumber; set => phoneNumber = value; }
        public OrderDetails Details { get => details; set => details = value; }

        public override bool Equals(object? obj)
        {
            Order? order = obj as Order;
            return order != null && order.GetHashCode() == this.GetHashCode();
        }

        public override int GetHashCode()
        {
            return Details.GetHashCode() + customer.GetHashCode();
        }
    }
}
